package top.yongyan0624.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.yongyan0624.Utils.RedisUtil;
import top.yongyan0624.common.lang.CodeMsg;
import top.yongyan0624.common.lang.ResultVO;
import top.yongyan0624.entity.Star;
import top.yongyan0624.service.StarService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yongyan
 * @since 2021-05-19
 */
@RestController
public class StarController extends BaseController {

    @Autowired
    private StarService starService;

    @PostMapping("/leavingMessage/star")
    public ResultVO star(@RequestBody Star star) {
        if (star.getMsgId() == null || star.getUserId() == null || star.getPostId() == null){
            return ResultVO.error(new CodeMsg("留言id、作者id、点赞者id不能为空！"));
        }

        starService.setStar(star);

        return ResultVO.success("操作成功!");
    }

    @PostMapping("/leavingMessage/getStarById")
    public ResultVO getStarById(@RequestBody Star star) {
        if (star.getMsgId() == null || star.getUserId() == null || star.getPostId() == null) {
            return ResultVO.error(new CodeMsg("留言id、作者id、点赞者id不能为空！"));
        }

        starService.handleCache(star);

        return ResultVO.success(star);
    }

}
